<?php

namespace backend\controllers;

/**
 * @author  shuang
 * @date    2016-8-5 9:53:59
 * @version V1.0
 * @desc    
 */
use common\components\BController;
use \backend\models\SystemForm;
use backend\models\TaskparamsForm;
use Yii;
use yii\helpers\ArrayHelper;

class SystemController extends BController {

    //站点设置
    public function actionSitesetting() {
        $model = new SystemForm();
        foreach ($model->attributes() as $attribute) {
            $model->$attribute = ArrayHelper::getValue(Yii::$app->params, $attribute);
        };
        $res = array("errors" => array(), "model" => $model);
        if (Yii::$app->request->isPost) {
            $model->load(Yii::$app->request->post());
            $flag = $model->updateParams();
            if ($flag !== false) {
                Yii::$app->getSession()->setFlash('success', '更新成功!');
            } else {
                $res = $flag;
                Yii::$app->getSession()->setFlash('error', $res["errors"]);
            }
        }
        //var_dump($res);exit;
        return $this->render("sitesetting", array_merge($res, array("action" => "sitesetting", "labels" => $model->attributeLabels())));
    }

    //unicode转换
    public function actionUtf8tounicode() {
        $string = Yii::$app->request->get("content");
        return $this->render("unicode", ["content" => json_encode($string)]);
    }
    /*
     * 任务参数配置
     */
    public function actionTaskparams(){
        $model = new TaskparamsForm();
        foreach ($model->attributes() as $attribute) {
            $model->$attribute = ArrayHelper::getValue(Yii::$app->params, $attribute);
        };
        $res = array("errors" => array(), "model" => $model);
        if (Yii::$app->request->isPost) {
            $model->load(Yii::$app->request->post());
            $flag = $model->updateParams();
            if ($flag !== false) {
                Yii::$app->getSession()->setFlash('success', '更新成功!');
            } else {
                $res = $flag;
                Yii::$app->getSession()->setFlash('error', $res["errors"]);
            }
        }
        return $this->render("taskparams",array_merge($res, array("action" => "taskparams", "labels" => $model->attributeLabels())));
    }

}
